class Solution(object):
    def longestDiverseString(self, a, b, c):
        # 初始化结果字符串和计数器
        result = []
        counts = {'a': a, 'b': b, 'c': c}
        
        # 当还有字符可用时继续循环
        while True:
            # 按剩余数量从大到小排序字符
            sorted_chars = sorted(counts.items(), key=lambda x: -x[1])
            
            # 获取剩余数量最多的字符
            most_char, most_count = sorted_chars[0]
            
            # 如果最多的字符数量为0，结束循环
            if most_count == 0:
                break
            
            # 如果结果字符串已经有两个连续的当前字符，选择下一个字符
            if len(result) >= 2 and result[-1] == result[-2] == most_char:
                next_char, next_count = sorted_chars[1]
                if next_count > 0:
                    result.append(next_char)
                    counts[next_char] -= 1
                else:
                    # 如果没有下一个可用字符，结束循环
                    break
            else:
                # 否则添加当前字符
                result.append(most_char)
                counts[most_char] -= 1
        
        return ''.join(result)